Ext.namespace("Sol");
Sol.menu = null;
Sol.west = null;
Sol.iframed = false;
Sol.onLoad = null;
Sol.onUnload = null;
Sol.layout = null;
Sol.layoutInterno=null;
Sol.toolbar = null;
Sol.title = 'titulo';
Sol.init = null;

var ALTO_HEADER = 70;
var ALTO_FOOTER = 24;

Sol.initMain = function (appsMenu) {
    if (Sol.init) Sol.init();
    Sol.layout = Sol.createLayout(appsMenu);

    if (Sol.menu!=null){
        Sol.menu.loadState();
    }
    Sol.controles.render(document);

    if (Sol.onLoad) Sol.onLoad();
    Sol.loadingShell(false);

};


Sol.createLayout = function(appsMenu) {
    var items = null;
    var informacion = null;
	var idDomHeader = 'header';
	var idDomFooter = 'footer';
	var idLinkEspolFiec = 'lefter';
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
    var norte = new Ext.BoxComponent({
        region:'north',
        el: idDomHeader,
        height:ALTO_HEADER,
        maxHeight: ALTO_HEADER,
        stateful:false
    });
    var sur = new Ext.BoxComponent({
        region:'south',
        el: idDomFooter,
        height:ALTO_FOOTER,
        maxHeight: ALTO_FOOTER,
        stateful:false
    });
    informacion = {
        title: Sol.title,
        region:'center',
        contentEl: 'informacion',
        autoScroll:true
    };

    /*Revisa si se muestra o no el menu*/
    if (appsMenu){
		var menu = {
			region:'center',
			id:'west-menu',
            rootVisible:false,
            autoScroll:true,
            animate: false
		};
        Sol.menu = new Sol.widgets.MainMenu(appsMenu,menu);
        Sol.west = {region:'west',
            id:'west-panel',
			title:'Menú',
			layout:'border',
            split:true,
            width: 250,
            minSize: 175,
            maxSize: 400,
            collapsible: true,
            stateful:true,
             backgroundColor:'#99ff99',
            //stateEvents:['expandnode'],
            //autoShow : true,
            margins:'0 0 0 5',
			items:[Sol.menu,{
				region:'south',
				contentEl:idLinkEspolFiec,
				height:80
			}]
        };
    }
	items = [informacion];
	if (Sol.iframed){
		document.getElementById(idDomHeader).style.display='None';
		document.getElementById(idDomFooter).style.display='None';
	}else{
		items.push(norte);
		items.push(sur);
	}
    if (Sol.west){
        items.push(Sol.west);
    }else{
		document.getElementById(idLinkEspolFiec).style.display='None';
	}
    /*Se crea el viewport*/
    var viewport = new Ext.Viewport({
        layout:'border',
        items: items,
        stateful:false
    });

    viewport.doLayout();
};
Sol.loadingShell = function(show) {
	var display;
	if (show) display = "block";
	else display = "none";
	Ext.get("loading-container").dom.style.display = display;
};
Sol.unloadShell = function(e) {
	Sol.loadingShell(true);
	if (Sol.onUnload) Sol.onUnload();
	if (!Sol.iframed && Sol.menu) (Sol.menu).saveState2();
};
